package com.zd.kids.ui.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hyy.libray.presenter.IBasePresenter;
import com.hyy.libray.ui.activity.BaseActivity;
import com.zd.kids.DataBean.BaseDataBean;
import com.zd.kids.DataBean.TestTrainWordResultDataBean;
import com.zd.kids.DataBean.TrainResultDataBean;
import com.zd.kids.R;
import com.zd.kids.net.CustomObserver;
import com.zd.kids.net.HttpMethod;
import com.zd.kids.ui.adapter.TrainResultAdapter;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

public class TrainResultActivity extends BaseActivity {

    @BindView(R.id.recycle_view)
    RecyclerView recycleView;

    @BindView(R.id.img_next)
    TextView imgNext;

    private TrainResultAdapter trainResultAdapter;

    public static final String UNIT_ID_KEY = "UNIT_ID_KEY";

    public static final String QUE_NAME_KEY = "QUE_NAME_KEY";

    public static final String RESULT_DATA_KEY = "RESULT_DATA_KEY";

    private String resultDatas;
    private String queName;

    /**
     * 获取布局文件地址
     */
    @Override
    public int getLayoutResId() {
        return R.layout.activity_train_result;
    }

    private List<TestTrainWordResultDataBean> testTrainResultDataBeans;

    /**
     * 初始化布局
     */
    @Override
    public void initView() {
        initTitle("", R.color.cartoon_title_color);

        resultDatas = getIntent().getStringExtra(RESULT_DATA_KEY);

        queName = getIntent().getStringExtra(QUE_NAME_KEY);

        if (!TextUtils.isEmpty(queName)) {
            tvTitle.setText(queName);
        }

        if (!TextUtils.isEmpty(resultDatas)) {
            testTrainResultDataBeans = new Gson().fromJson(resultDatas, new TypeToken<List<TestTrainWordResultDataBean>>() {
            }.getType());
        }

        imgBack.setVisibility(View.GONE);

        imgNext.setOnClickListener(view -> finish());


        initRecycle(testTrainResultDataBeans);

    }

    private void initRecycle(List<TestTrainWordResultDataBean> itemDatas) {
        if (itemDatas == null) {
            itemDatas = new ArrayList<>();
        }
        recycleView.setLayoutManager(new LinearLayoutManager(this));
        trainResultAdapter = new TrainResultAdapter(itemDatas);
        View headerView = getLayoutInflater().inflate(R.layout.activity_train_result_header, null);
        trainResultAdapter.setHeaderView(headerView);
        recycleView.setAdapter(trainResultAdapter);

    }

    /**
     * 获取Presenter，不用MVP，可以为空
     *
     * @return
     */
    @Override
    protected IBasePresenter onBasePresenter() {
        return null;
    }


}
